import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { BaseResponse, PagerResponse } from '@/api/base';
import { QuestionOptionRequest } from '@/api/exam/questionOption'

// 定义接口地址
enum Api {
  /** 批量删除 */
  BATCH_DELETE = '/exam/question/batchDelete',
  /** 删除 */
  DELETE_BY_ID = '/exam/question/delete/',
  /** 查询基本信息 */
  DETAIL = '/exam/question/',
  /** 列表查询 */
  LIST = '/exam/question/list',
  /** 分页查询 */
  PAGER = '/exam/question/pager',
  /** 新增 */
  SAVE = '/exam/question/save',
  /** 修改 */
  UPDATE = '/exam/question/update/',
}

// 定义参数类型

export interface QuestionDO {
  id?: number;
  creator?: String;
  createTime?: Date;
  updater?: String;
  updateTime?: Date;
  title?: String;
  subTitle?: String;
  type?: number;
  answer?: String;
  category?: String;
  status?: number;
  remark?: String;
}

export interface QuestionQuery {
  id?: number;
  creator?: String;
  createTime?: Date;
  updater?: String;
  updateTime?: Date;
  title?: String;
  subTitle?: String;
  type?: number;
  answer?: String;
  category?: String;
  status?: number;
  remark?: String;
}

export interface QuestionRequest {
  id?: number;
  creator?: String;
  createTime?: Date;
  updater?: String;
  updateTime?: Date;
  title?: String;
  subTitle?: String;
  type?: number;
  answer?: String;
  category?: String;
  status?: number;
  remark?: String;
  options?:QuestionOptionRequest[];
}

// 定义接口方法: save
// 批量删除
export function batchDelete(params: number[], mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<number>>(
    {
      url: Api.BATCH_DELETE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 删除
export function deleteById(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.delete<BaseResponse<boolean>>(
    {
      url: Api.DELETE_BY_ID + '/' + id,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 查询基本信息
export function detail(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BaseResponse<QuestionDO>>(
    {
      url: Api.DETAIL + '/' + id,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 列表查询
export function list(params: QuestionQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<Array<QuestionDO>>>(
    {
      url: Api.LIST,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 分页查询
export function pager(params: QuestionQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<PagerResponse<QuestionDO>>>(
    {
      url: Api.PAGER,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 新增
export function save(params: QuestionRequest, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<number>>(
    {
      url: Api.SAVE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 修改
export function update(id: number | undefined, params: QuestionRequest, mode: ErrorMessageMode = 'message') {
  return defHttp.put<BaseResponse<boolean>>(
    {
      url: Api.UPDATE + '/' + id,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

